package ezy.lite.util;

import android.os.Bundle;
import android.os.Parcelable;

public class Param {
    private static final String PARAM = "__PARAM__";

    public static Bundle bundle(Bundle bundle, boolean value) {
        bundle.putBoolean(PARAM, value);
        return bundle;
    }

    public static Bundle bundle(Bundle bundle, int value) {
        bundle.putInt(PARAM, value);
        return bundle;
    }

    public static Bundle bundle(Bundle bundle, float value) {
        bundle.putFloat(PARAM, value);
        return bundle;
    }

    public static Bundle bundle(Bundle bundle, long value) {
        bundle.putLong(PARAM, value);
        return bundle;
    }

    public static Bundle bundle(Bundle bundle, String value) {
        bundle.putString(PARAM, value);
        return bundle;
    }

    public static Bundle bundle(Bundle bundle, Parcelable value) {
        bundle.putParcelable(PARAM, value);
        return bundle;
    }


    public static Bundle bundle(boolean value) {
        Bundle bundle = new Bundle();
        bundle.putBoolean(PARAM, value);
        return bundle;
    }

    public static Bundle bundle(float value) {
        Bundle bundle = new Bundle();
        bundle.putFloat(PARAM, value);
        return bundle;
    }

    public static Bundle bundle(int value) {
        Bundle bundle = new Bundle();
        bundle.putInt(PARAM, value);
        return bundle;
    }

    public static Bundle bundle(long value) {
        Bundle bundle = new Bundle();
        bundle.putLong(PARAM, value);
        return bundle;
    }

    public static Bundle bundle(String value) {
        Bundle bundle = new Bundle();
        bundle.putString(PARAM, value);
        return bundle;
    }

    public static Bundle bundle(Parcelable value) {
        Bundle bundle = new Bundle();
        bundle.putParcelable(PARAM, value);
        return bundle;
    }


    public static boolean get(Bundle bundle, boolean def) {
        return bundle == null ? def : bundle.getBoolean(PARAM, def);
    }

    public static float get(Bundle bundle, float def) {
        return bundle == null ? def : bundle.getFloat(PARAM, def);
    }

    public static int get(Bundle bundle, int def) {
        return bundle == null ? def : bundle.getInt(PARAM, def);
    }

    public static long get(Bundle bundle, long def) {
        return bundle == null ? def : bundle.getLong(PARAM, def);
    }

    public static String get(Bundle bundle, String def) {
        if (bundle == null) {
            return def;
        }
        String result = bundle.getString(PARAM);
        return result == null ? def : result;
    }

    public static <T extends Parcelable> T get(Bundle bundle) {
        return bundle == null ? null : (T) bundle.getParcelable(PARAM);
    }
}
